<template>
  <a-modal
    title="分配金额"
    :width="1000"
    :visible="visible"
    :confirmLoading="false"
    @ok="() => ok()"
    @cancel="() => { $emit('cancel') }">
    <a-spin :spinning="false">
      <a-form
        :form="form"
        v-bind="formLayout">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="选择分配人员">
              <a-select
                placeholder="请选择分配人员"
                v-decorator="['userId',{ rules: [{ required: true, message: '请选择分配人员' }] }]">
                <a-select-option
                  v-for="row in allUsers"
                  :key="row.userId"
                  :value="row.userId">{{ row.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="分配权重">
              <a-input-number
                style="width: 100%"
                placeholder="输入固定分配比例"
                :min="0"
                :max="1"
                :precision="2"
                v-decorator="['rate', { rules:
                  [{ required: true,
                     message: '请输入分配比例' }] }]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="备注">
              <a-textarea
                style="width: 100%"
                placeholder="请输入"
                v-decorator="['note']" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
// import { getYearsVersion } from '@/api/performanceConfig'
// 表单字段
const fields = ['version']

export default {
  name: 'UserForm',
  components: {},
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    allUsers: {
      type: Array,
      default: () => []
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 20 },
        sm: { span: 13 }
      }
    }
    return {
      form: this.$form.createForm(this)
    }
  },
  mounted () {
  },
  created () {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))
  },
  watch: {},
  methods: {
    ok () {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$emit('ok', values)
        }
      })
    }
  }
}
</script>
